﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hrEmpScheduling.aspx.cs" Inherits="ZX.WebApp.EHR.hrEmpScheduling" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>员工排班</title>
    <link href="../Styles/table_style.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
     <script type="text/javascript" src="../Scripts/Jquery.form.js"></script>
     <script type="text/javascript" src="../Scripts/CombinButton.js"></script>
     <script src="../Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>

    <script type="text/javascript">
    // <![CDATA[
        $(document).ready(function () {
            parent.document.getElementById("dialog1_h").innerHTML = "员工排班";
            GetWorkTimeSelect();
            addtr();
        });

        //取得班次下拉数据
        function GetWorkTimeSelect() {
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=GetWorkTimeSelect", {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        $("#WorkTimeID").append(str);
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }

        //选择员工
        var employeeId;
        var ValueChanged = function (rowobj) {
            employeeId = $("#empId").val();
        }

        var TextChanged = function (rowobj) {
            var employeeName = $("#txtempId").val();
            if (employeeId == "" || employeeId == "undefined") {
                return;
            }
            if (employeeName == "" || employeeName == "undefined") {
                return;
            }
            //debugger
            $("#txtEmployeeID", rowobj).val(employeeName);
            $("#EmployeeID", rowobj).val(employeeId);
            GetDeptNameByEmpID(employeeId);
            GetPostNameByEmpID(employeeId);
            GetEmpcodeByEmpID(employeeId);
        }

        //获取员工所属部门名称
        function GetDeptNameByEmpID(empId) {
            var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
            $.get(url, function (d, s) {
                var list = eval("(" + d + ")");
                for (var o in list.rows) {
                    var t = list.rows[o].DeptName;
                    if (typeof (t) != "undefined") {
                        $("#DeptName", rowobj).val(t);
                    }
                }
            });
        }

        //获取员工所属岗位名称
        function GetPostNameByEmpID(empId) {
            var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
            $.get(url, function (d, s) {
                var list = eval("(" + d + ")");
                for (var o in list.rows) {
                    var t = list.rows[o].PostName;
                    if (typeof (t) != "undefined") {
                        $("#PostName", rowobj).val(t);
                    }
                }
            });
        }

        //获取员工编号
        function GetEmpcodeByEmpID(empId) {
            var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
            $.get(url, function (d, s) {
                var list = eval("(" + d + ")");

                for (var o in list.rows) {
                    var t = list.rows[o].EmployeeCode;
                    if (typeof (t) != "undefined") {
                        $("#EmployeeCode", rowobj).val(t);
                    }
                }

            });
        }

        //增加行
        function addtr() {
            var tr = $("#tbEmp tr").eq(1).clone();
            tr.show();
            tr.appendTo("#tbEmp").removeClass("selectedTr").find(":checkbox").attr("checked", false);
        }

        //删除行
        function deltr() {
            //遍历tr
            $("#tbEmp tr").first().nextAll().each(function () {
                if ($(this).hasClass("selectedTr")) {
                    $(this).remove();
                }
            });
        };

        //选中行
        $("#tbEmp tr").live("click", function () {
            if ($(this).hasClass("selectedTr")) {
                $(this).removeClass("selectedTr").find(":checkbox").attr("checked", false);
            } else {
                $(this).addClass("selectedTr").find(":checkbox").attr("checked", true);
            }
        });

        //数据保存
        function Save() {
            //debugger;
            var beginDate = $("#BeginWorkDate").val();
            var endDate = $("#EndWorkDate").val();
            var workTimeID = $("#WorkTimeID").val();
            //alert("workTimeID:"+workTimeID);
            var ids = "";

            if (beginDate == "") {
                alert("开始日期为空！");
                return;
            }
            if (endDate == "") {
                alert("结束日期为空！");
                return;
            }
            if (workTimeID == "") {
                alert("班次为空！");
                return;
            }

            //遍历所有已选择员工
            $("#tbEmp tr").first().nextAll().each(function () {
                var id = $("#EmployeeID", this).val();
                if ($("#EmployeeID", this).val() != "") {
                    ids += "," + id;
                }
            });
            if (ids != "") {
                ids = ids.substring(1, ids.length);
            }
            else {
                alert("请至少选择一个员工！");
                return;
            }

            //提交数据
            YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=saveScheduling&ids=" + ids + "&beginDate=" + beginDate + "&endDate=" + endDate+"&workTimeID="+workTimeID, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str.substring(0, 1) == "1") {
                            alert("数据保存成功!");
                            parent.closeWin();
                            parent.ReLoadData();
                        }
                        else {
                            alert("数据保存失败,请检查");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
    // ]]> 
     </script>
     <style type="text/css">
    body{font-family: 宋体, Arial, Helvetica, sans-serif;font-size: 12px;color: #333333;background-color: #FFFFFF;} 
    select{width:99%;} td { border: 1px solid #CCCCCC;}
    .textarea{ width: 96%;height: 25px;}	
   .selectedTr{  background-color: blue;} 
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <input id="empId" name="empId" type="hidden" /> <input id="txtempId" name="txtempId" type="hidden" />
    <table align="center" class="TableBlock" width="99%" id="tbMain" name="tbMain">
		    <tr>
			    <td align="left" class="TableData" width="200">开始日期</td>
			    <td align="left" class="TableContent">
                    <input class="td_value3"  id="BeginWorkDate" name="BeginWorkDate" onclick="WdatePicker()" style="width: 120px" type="text" />
                </td>
		    </tr>
		    <tr>
			    <td align="left" class="TableData" width="200">结束日期</td>
			    <td align="left" class="TableContent">
                    <input class="td_value3"  id="EndWorkDate" name="EndWorkDate" onclick="WdatePicker()" style="width: 120px" type="text" />
                </td>
		    </tr>
            <tr>
			    <td align="left" class="TableData" width="200">班次</td>
			    <td align="left" class="TableContent">
                <select id="WorkTimeID" name="WorkTimeID" style="width: 150px;" >
                </select>
                </td>
            </tr>
    </table>
    <div id="divBtn">
        <input type="button" id="btnADD" value="新增" onclick="addtr();" />
        <input type="button" id="btnDEL" value="删除" onclick="deltr();" />
    </div>
    <table align="center" border="1" id="tbEmp" name="tbEmp" style="border-collapse: collapse" width="99%">
        <tr id="data_head" style="background-color: #e4e7e2">
           <td style="text-align: center"></td>
	        <td style="text-align: center">员工姓名</td>
	        <td style="text-align: center">员工编号</td>
	        <td style="text-align: center">部门</td>
	        <td style="text-align: center"> 岗位</td>
        </tr>
        <tr style="display:none">
            <td>
                <input type="checkbox" id="chktr" name="chktr" />
            </td>
	        <td>
		        <input  id="EmployeeID" name="EmployeeID" type="hidden" value="" />
                <input  id="txtEmployeeID" name="txtEmployeeID" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
                <button id="btnempId" name="emp" onclick="SelectEmployee(this);" type="button">选择</button>
            </td>
	        <td>
		        <input  id="EmployeeCode" name="EmployeeCode" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
	        <td>
		        <input id="DeptName" name="DeptName" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
	        <td>
		        <input id="PostName" name="PostName" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
